package com.rabbitmq.exec.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.rabbitmq.exec.utils.RabbitMqUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Scanner;

/**
 * @Description
 * @Author lhj
 * @Date 2024/4/13 21:53
 */
public class Task02 {

    static final Logger logger = LoggerFactory.getLogger(Task02.class);
    
    public static final String ACK_QUEUE_NAME = "ack.queue";
    public static void main(String[] args) throws Exception {
        try (Channel channel = RabbitMqUtils.getChannel()){
            boolean durable = true;
            channel.queueDeclare(ACK_QUEUE_NAME, durable, false, false, null);
            Scanner sc = new Scanner(System.in);
            while (sc.hasNext()) {
                String message = sc.next();
                channel.basicPublish("", ACK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes("UTF-8"));
                logger.info("生产者task02发送消息, 队列: {}, 消息: {}", ACK_QUEUE_NAME, message);
            }
        }
    }
}
